new Vue({
  el: "#app",
  data() {
    return {
      sjTotal: 0,
      ye: 1, //绑定初始页数
      SQL: "select * from business_column where Row_Status='0'",
      form: {
        page:1,
        limit:10,
        SQLSerialNumber: "P_business_column",
        PaginationNumber: 1, //页数
        RowAmount: 10, //每页数据条数
        Column_Name: "",
        Condition: "",
        ExtensionCondition: "",
      },
      total: 0,
      tableData: [], //表格数据
    };
  },
  mounted() {
    this.getList(); //前端分页
  },
  methods: {
    onSerach() {
      //查询方法
      this.form.PaginationNumber = 1;
      this.getList();
    },
    Add() {
      window.location.href = "./add.html";
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
    },
    handleCurrentChange(val){
      this.form.page = val;
    },
    sjhandleCurrentChange(val) {
      this.form.PaginationNumber = val;
      //   this.getList();
    },
    getList() {
      //换页方法
      const that = this;
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumberWithOriginal`,
        // url: "https://service.kdddy.cn/donghui/login/generalQueryByTableNameAndPaginationForClient",
        data: {
          SQLSerialNumber: "A_business_Quotation1", //表名
          Condition: "",
          ExtensionCondition:'',
        },
        success: function (Result) {
          const filteredData =
          Result?.filter((item) => {
            const score = item.Score;
            return score !== undefined && score !== null && score !== "";
          }) || [];
        that.tableData = that.tableData?.concat(filteredData) || filteredData;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      // $.ajax({
      //   headers: {
      //     AccessToken: $.cookie("token"), //会将数据转换为query string
      //   },
      //   // url: `https://service.kdddy.cn/donghui/login/generalQueryByTableNameAndPaginationForClient`,
      //   url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
      //   type: "POST",
      //   data: {
          
      //     Data: "business_Contract", //表名
      //     Condition: "Evaluate_Status <>1",
      //   },
      //   success: function (Result) {
      //     console.log(Result);

      //     //   that.tableData = Result;
         
      //     console.log(that.tableData);
      //     //   that.total = Result.Total;
      //   },
      //   complete: function (XMLHttpRequest) {
      //     requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
      //   },
      //   dataType: "json",
      // });
    },
    Edit(Column_SerialNumber) {
      sessionStorage.setItem("Column_SerialNumber", Column_SerialNumber);
      window.location.href =
        "./edit.html?Column_SerialNumber=" + Column_SerialNumber;
    },
    Remove(row) {
      console.log(row);

      const that = this;
      this.$confirm("警告！此操作将删除该评论, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          row.Evaluate_Status = "1";
          console.log(row);

          //   return;
          $.ajax({
            headers: {
              AccessToken: $.cookie("token"), //会将数据转换为query string
            },
            url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
            type: "POST",
            data: {
              Data: "business_Contract" ,
              Condition: "ContractID='" + row.ContractID + "'"
            },
            success: function (res) {
              res[0].Evaluate_Status = "1";
              $.ajax({
                headers: {
                  AccessToken: $.cookie("token"), //会将数据转换为query string
                },
                url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
                type: "POST",
                data: {
                  Data: JSON.stringify({ Modify: { business_Contract: res } }),
                },
                success: function (res) {
                  console.log(res);
    
                  if (res.Status === "success") {
                    that.$message({
                      type: "success",
                      message: "删除成功!",
                    });
                  } else {
                    that.$message.error("删除失败，请稍后再试");
                  }
                },
                complete: function (XMLHttpRequest) {

                  requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
                },
                dataType: "json",
              });
            },
            complete: function (XMLHttpRequest) {

              requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
            },
            dataType: "json",
          });
          
        })
        .catch(() => {});
    },
    Remove1(row) {
      const that = this;
      row.Evaluate_Status = (row.Evaluate_Status=='0'?"2":'0');
      console.log(row);

      //   return;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        type: "POST",
        data: {
          Data: "business_Contract" ,
          Condition: "ContractID='" + row.ContractID + "'"
        },
        success: function (res) {
          res[0].Evaluate_Status = row.Evaluate_Status;
          $.ajax({
            headers: {
              AccessToken: $.cookie("token"), //会将数据转换为query string
            },
            url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
            type: "POST",
            data: {
              Data: JSON.stringify({ Modify: { business_Contract: res } }),
            },
            success: function (res) {
              console.log(res);

              if (res.Status === "success") {
                that.$message({
                  type: "success",
                  message: "操作成功!",
                });
              } else {
                that.$message.error("删除失败，请稍后再试");
              }
            },
            complete: function (XMLHttpRequest) {

              requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
            },
            dataType: "json",
          });
        },
        complete: function (XMLHttpRequest) {

          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
  },
});
